//
//  sendDetailViewController.m
//  OfferJob
//
//  Created by 河南动力无限科技有限公司 on 17/7/10.
//  Copyright © 2017年 郑州动力无限科技. All rights reserved.
//

#import "sendDetailViewController.h"
#import "CellView.h"
#import "companyDetailsViewController.h"
@interface sendDetailViewController ()
@property (nonatomic,strong)UIScrollView* scrollView;
@property(nonatomic,strong)UILabel *titleLB;
@property(nonatomic,strong)UILabel *moneyLB;
@property(nonatomic,strong)UILabel *dayLB;
@property(nonatomic,assign)float aa;
@property(nonatomic,strong)NSMutableDictionary* dic;
@property(nonatomic,strong)NSString* telestr;
@end

@implementation sendDetailViewController

- (void)viewDidLoad {
    self.title=@"任务详情";
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64)];
    _scrollView.backgroundColor=backgroundcolor;
        _scrollView.userInteractionEnabled=YES;
    [self.view addSubview:_scrollView];
    _dic=[[NSMutableDictionary alloc]init];
    

    
    [self getUserInfo];
}

// 获取
-(void)getUserInfo{
    FXTHttpRequestModel * requestModel = [[FXTHttpRequestModel alloc] init];
    requestModel.type = FXTHttpType_GET;
    requestModel.appendUrl = @"/Task/taskinfo";
    NSMutableDictionary * paramDic = [NSMutableDictionary dictionary];
    [paramDic setValue:self.strID forKey:@"task_id"];
    requestModel.paramDic = paramDic;
    requestModel.callback = ^(FXTHttpResponseModel * result, NSError *error){
        if (result.state ==FXTReponseCodeState_Success) {
            NSLog(@"请wwww%@",result.data);
            _dic=result.data;
            [self setUI];
            [_scrollView refreshControl];
  
        }else {
            [DisplayHelper displayWarningAlert:result.alertMsg];
        }
    };
    [[FXTHttpSessionManager sharedHttpSessionManager] sendHttpRequestParam:requestModel];
}





- (void)setUI{
    UIView* firstV=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 90*kAppScale)];
    firstV.backgroundColor=[UIColor whiteColor];
    UITapGestureRecognizer* singleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tuPianBtnClick)];
    singleRecognizer.numberOfTapsRequired = 1; // 单击
    
    [firstV addGestureRecognizer:singleRecognizer];
    [_scrollView  addSubview:firstV];

//    WithFrame:CGRectMake(0, setY, SCREEN_WIDTH, 200*kAppScale)]
    UIView*secendtV=[[UIView alloc]init];
    secendtV.backgroundColor=[UIColor whiteColor];
    secendtV.userInteractionEnabled=YES;
    [_scrollView  addSubview:secendtV];
    
    
    UIView*thirdV=[[UIView alloc]init];
    thirdV.backgroundColor=[UIColor whiteColor];
    [_scrollView  addSubview:thirdV];
    
    
    
    
    _titleLB=[[UILabel alloc]initWithFrame:CGRectMake(10*kAppScale, 10*kAppScale,SCREEN_WIDTH-10*kAppScale, 35*kAppScale)];
    _titleLB.textColor=[UIColor blackColor];
    _titleLB.textAlignment=NSTextAlignmentLeft;
    _titleLB.font=[UIFont systemFontOfSize:16*kAppScale];
    _titleLB.text=[NSString stringWithFormat:@"%@",[_dic objectForKey:@"title"]];
    [firstV addSubview:_titleLB];
 
    
    
    NSString* dayname;
    if ([[_dic objectForKey:@"jiesuan_unit"]isEqualToString:@"1"]) {
        dayname=@"天";
    }else if ([[_dic objectForKey:@"jiesuan_unit"]isEqualToString:@"2"]) {
        dayname=@"小时";
    }else  if ([[_dic objectForKey:@"jiesuan_unit"]isEqualToString:@"3"]){
        dayname=@"次";
    }else{
       dayname=@"预算";
    }
    
    _moneyLB=[[UILabel alloc]initWithFrame:CGRectMake(10*kAppScale,_titleLB.bottom,SCREEN_WIDTH-10*kAppScale, 20*kAppScale)];
    _moneyLB.textColor=[UIColor redColor];
    _moneyLB.textAlignment=NSTextAlignmentLeft;
    _moneyLB.text=[NSString stringWithFormat:@"%@元/%@",[_dic objectForKey:@"jiesuan_price"],dayname];
    _moneyLB.font=[UIFont systemFontOfSize:15*kAppScale];
    [firstV addSubview:_moneyLB];
    
    
    
    UIImageView* image=[[UIImageView alloc]initWithFrame:CGRectMake(340, 35, 16, 16)];
    image.image=[UIImage imageNamed:@"icon_jtt"];
    [firstV  addSubview:image];
    

    NSString * danWei;
    if ([[_dic objectForKey:@"jiesuan_type"]isEqualToString:@"1"]) {
        danWei=@"日结";
    }else if ([[_dic objectForKey:@"jiesuan_type"]isEqualToString:@"2"]){
        danWei=@"小时结";
        
    }else if ([[_dic objectForKey:@"jiesuan_type"]isEqualToString:@"3"]){
        danWei=@"次结";
        
    }else if ([[_dic objectForKey:@"jiesuan_type"]isEqualToString:@"4"]){
        danWei=@"完工结";
        
    }
    NSString* str=   [NSString stringWithFormat:@"%@人",[_dic objectForKey:@"num"]];
      NSString* strTwo=   [NSString stringWithFormat:@"%@",[_dic objectForKey:@"worktype"]];
                      
    _dayLB=[[UILabel alloc]initWithFrame:CGRectMake(10*kAppScale,_moneyLB.bottom,SCREEN_WIDTH-10*kAppScale, 20*kAppScale)];
    _dayLB.textColor=grayTextColor;
    _dayLB.text=[NSString stringWithFormat:@"%@|%@|%@",strTwo,str,danWei];
    _dayLB.textAlignment=NSTextAlignmentLeft;
    _dayLB.font=[UIFont systemFontOfSize:13*kAppScale];
    [firstV addSubview:_dayLB];

    
    float setY=firstV.bottom;
    setY+=10;
    

    NSArray *firstArr=@[@" ",@"工作日期:",@"工作时间:",@"工作地点:"];
    NSArray *firsArr=@[@" ",[NSString stringWithFormat:@"%@",[_dic objectForKey:@"date_time"]],[NSString stringWithFormat:@"%@",[_dic objectForKey:@"hour_time"]],[NSString stringWithFormat:@"%@",[_dic objectForKey:@"address"]]];
 
    for (int i=0; i<[firstArr count]; i++) {
        CellView *cell=[[CellView alloc]initWithFrame:CGRectMake(0, setY, self.view.width, 44*kAppScale)];
        cell.titleLabel.textColor=grayTextColor;
        cell.titleLabel.font=[UIFont  systemFontOfSize:13*kAppScale];
        cell.titleLabel.text=[firstArr objectAtIndex:i];
        cell.titleLabel.textAlignment=NSTextAlignmentLeft;
        cell.contentLabel.textColor=blackTextColor;
        cell.contentLabel.text=[firsArr objectAtIndex:i];
        cell.userInteractionEnabled=YES;
        if (i==0) {
            cell.titleLabel.hidden=YES;
             cell.contentLabel.hidden=YES;
            cell.frame=CGRectMake(0, setY, self.view.width, 70*kAppScale);
        UIImageView* imageView=[[UIImageView alloc]initWithFrame:CGRectMake(10*kAppScale, 10*kAppScale, 50*kAppScale, 50*kAppScale)];
        imageView.image=[UIImage imageNamed:@"icon_bjj"];
            [imageView setImageWithURL:[NSURL URLWithString:[_dic objectForKey:@"header_pic"]] placeholderImage:[UIImage imageNamed:@"icon_bjj"]];
        imageView.layer.cornerRadius=imageView.height/2;
         imageView.clipsToBounds=YES;
            imageView.userInteractionEnabled=YES;

        [cell  addSubview:imageView];
        
        UILabel*nameLB=[[UILabel alloc]initWithFrame:CGRectMake(imageView.right+10*kAppScale,10*kAppScale,300*kAppScale, 30*kAppScale)];
        nameLB.textColor=blackTextColor;
            nameLB.text=[NSString stringWithFormat:@"%@",[_dic objectForKey:@"name"]];
        nameLB.textAlignment=NSTextAlignmentLeft;
        nameLB.font=[UIFont systemFontOfSize:14*kAppScale];
        [cell addSubview:nameLB];
        
            
            
            
        UIImageView* imageTu=[[UIImageView alloc]initWithFrame:CGRectMake(imageView.right+10*kAppScale, nameLB.bottom, 20*kAppScale, 20*kAppScale)];
            if ([[_dic objectForKey:@"is_deposit"]isEqualToString:@"2"]) {
                imageTu.image=[UIImage imageNamed:@"icon_jnbzj"];
            }else{
                imageTu.image=[UIImage imageNamed:@"icon_bozj"];
            }
        [cell  addSubview:imageTu];
        
        
        UILabel*titleLB=[[UILabel alloc]initWithFrame:CGRectMake(imageTu.right+10*kAppScale,nameLB.bottom,100*kAppScale, 20*kAppScale)];
        titleLB.textColor=grayTextColor;
        titleLB.textAlignment=NSTextAlignmentLeft;
            titleLB.text=[NSString stringWithFormat:@"%@",[_dic objectForKey:@"content"]];
        titleLB.font=[UIFont systemFontOfSize:13*kAppScale];
        [cell addSubview:titleLB];
           
            
//     UIButton* secendView=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 70*kAppScale)];
//            secendView.userInteractionEnabled=YES;
//       [secendView addTarget:self action:@selector(btn) forControlEvents:UIControlEventTouchUpInside];
//            secendView.backgroundColor=[UIColor redColor];
//        [cell  addSubview:secendView];
//            [cell  bringSubviewToFront:secendView];
            

            

          }
        
        if (i==3) {
            
           UIImageView*RightImg=[[UIImageView alloc]initWithFrame:CGRectMake  (335*kAppScale,13*kAppScale, 16*kAppScale, 16*kAppScale)];
            RightImg.hidden=NO;
            RightImg.image=[UIImage imageNamed:@"icon_dingw"];
            RightImg.contentMode=UIViewContentModeScaleAspectFit;
            [cell addSubview:RightImg];
        
        }
        [secendtV addSubview:cell];
        setY=cell.bottom;
        secendtV.height=setY;
    }
    
    setY+=10*kAppScale;
    
    NSArray *MArrl=@[@"联系人:",@"电话:"];
    _telestr=[NSString stringWithFormat:@"%@",[_dic objectForKey:@"tel"]];
    NSArray *VArrl=@[[NSString stringWithFormat:@"%@",[_dic objectForKey:@"user_name"]],_telestr];
    for (int i=0; i<[MArrl count]; i++) {
        CellView *cell=[[CellView alloc]initWithFrame:CGRectMake(0, setY, self.view.width, 44*kAppScale)];
        cell.titleLabel.textColor=grayTextColor;
        cell.titleLabel.font=[UIFont  systemFontOfSize:13*kAppScale];
        cell.titleLabel.text=[MArrl objectAtIndex:i];
        cell.titleLabel.textAlignment=NSTextAlignmentLeft;
        cell.contentLabel.textColor=blackTextColor;
        cell.contentLabel.text=[VArrl objectAtIndex:i];
        //        cell.contentLabel.frame=CGRectMake(cell.titleLabel.right+80*self.scale, 0, 80*self.scale, 44*self.scale);
        [thirdV addSubview:cell];
        setY=cell.bottom;
        
        if (i==1) {
            UIButton *nextBtn=[[UIButton alloc]initWithFrame:CGRectMake(180*kAppScale,12*kAppScale,20*kAppScale,20*kAppScale)];
            [nextBtn setImage:[UIImage imageNamed:@"icon_dianhua"] forState:UIControlStateNormal];
            [nextBtn addTarget:self action:@selector(teleEvent) forControlEvents:UIControlEventTouchUpInside];
            [cell addSubview:nextBtn];
        }
 
        
    }

    
    
    
    
    
    setY+=10*kAppScale;
    
    NSString* sex;
    if ([[_dic objectForKey:@"need_sex"]isEqualToString:@"1"]) {
        sex=@"男";
    }else if ([[_dic objectForKey:@"need_sex"]isEqualToString:@"1"]) {
        sex=@"女";
    }else{
    sex=@"不限";
    }
    
       NSArray *MArr=@[@"招聘人数:",@"性别要求:",@"任务薪酬:",@"结算方式:"];
           NSArray *VArr=@[[NSString stringWithFormat:@"%@人",[_dic objectForKey:@"num"]],sex,[NSString stringWithFormat:@"%@元/%@",[_dic objectForKey:@"jiesuan_price"],dayname],danWei];
    for (int i=0; i<[MArr count]; i++) {
        CellView *cell=[[CellView alloc]initWithFrame:CGRectMake(0, setY, self.view.width, 44*kAppScale)];
        cell.titleLabel.textColor=grayTextColor;
        cell.titleLabel.font=[UIFont  systemFontOfSize:13*kAppScale];
        cell.titleLabel.text=[MArr objectAtIndex:i];
        cell.titleLabel.textAlignment=NSTextAlignmentLeft;
        cell.contentLabel.textColor=blackTextColor;
         cell.contentLabel.text=[VArr objectAtIndex:i];
//        cell.contentLabel.frame=CGRectMake(cell.titleLabel.right+80*self.scale, 0, 80*self.scale, 44*self.scale);
     [thirdV addSubview:cell];
          setY=cell.bottom;
    }
   
 setY=10*kAppScale+setY;
    _aa=setY;
    UIView*foruV=[[UIView alloc]initWithFrame:CGRectMake(0,_aa, SCREEN_WIDTH,300*kAppScale)];
    foruV.backgroundColor=[UIColor whiteColor];
    [_scrollView  addSubview:foruV];

    
    UILabel*nLB=[[UILabel alloc]initWithFrame:CGRectMake(10*kAppScale,10*kAppScale,200*kAppScale, 30*kAppScale)];
    nLB.textColor=[UIColor blackColor];
    nLB.text=@"任务描述";
    nLB.textAlignment=NSTextAlignmentLeft;
    nLB.font=[UIFont systemFontOfSize:14*kAppScale];
    [foruV addSubview:nLB];
    
    UILabel*namLBt=[[UILabel alloc]initWithFrame:CGRectMake(10*kAppScale,nLB.bottom,SCREEN_WIDTH-20*kAppScale, 60*kAppScale)];
    namLBt.textColor=grayTextColor;
    namLBt.text=[NSString stringWithFormat:@"%@人",[_dic objectForKey:@"content"]];
    namLBt.textAlignment=NSTextAlignmentLeft;
    namLBt.font=[UIFont systemFontOfSize:14*kAppScale];
    namLBt.numberOfLines = 0;
    [foruV addSubview:namLBt];
    
    UIView* linevi=[[UIView alloc]initWithFrame:CGRectMake(10*kAppScale, namLBt.bottom+10*kAppScale, SCREEN_WIDTH-20*kAppScale, 0.5)];
    linevi.backgroundColor=blackLineColore;
    [foruV addSubview:linevi];
    
    UILabel*namLBW=[[UILabel alloc]initWithFrame:CGRectMake(10*kAppScale,linevi.bottom,SCREEN_WIDTH,44*kAppScale)];
    namLBW.textColor=blackTextColor;
    namLBW.text=[NSString stringWithFormat:@"报名截止:   %@",[_dic objectForKey:@"enroll_endtime"]];
    namLBW.textAlignment=NSTextAlignmentLeft;
    namLBW.font=[UIFont systemFontOfSize:14*kAppScale];
    [foruV addSubview:namLBW];
    
    UIView* viewe=[[UIView alloc]initWithFrame:CGRectMake(10*kAppScale, namLBW.bottom, SCREEN_WIDTH-20*kAppScale, 0.5)];
    viewe.backgroundColor=blackLineColore;
    [foruV addSubview:viewe];

    UIView* vieww=[[UIView alloc]initWithFrame:CGRectMake(10*kAppScale, viewe.bottom, SCREEN_WIDTH-20*kAppScale,60*kAppScale)];
    vieww.backgroundColor=backgroundcolor;
    [foruV addSubview:vieww];
    
    
    UILabel*nat=[[UILabel alloc]initWithFrame:CGRectMake(10*kAppScale,0,SCREEN_WIDTH-20*kAppScale, 60*kAppScale)];
    nat.textColor=grayTextColor;
    nat.text=@"注：商家不会以形式进行收费，若商家要求缴纳费用，请提高警惕！";
    nat.textAlignment=NSTextAlignmentLeft;
    nat.font=[UIFont systemFontOfSize:14*kAppScale];
    nat.numberOfLines = 0;
    [vieww addSubview:nat];
    
    UIButton *nextBtn=[[UIButton alloc]initWithFrame:CGRectMake(10*kAppScale,vieww.bottom+ 10*kAppScale,SCREEN_WIDTH-20*kAppScale,44*kAppScale)];
    nextBtn.backgroundColor=NavCOLOR;
//    if ([[_dic objectForKey:@"status"]isEqualToString:@"1"]) {
//        nextBtn.userInteractionEnabled=YES;
//    }else if ([[_dic objectForKey:@"status"]isEqualToString:@"2"]){
//    nextBtn.userInteractionEnabled=NO;
//         nextBtn.backgroundColor=grayTextColor;
//    }
    [nextBtn setTitle:@"我要报名" forState:UIControlStateNormal];
    [nextBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    nextBtn.titleLabel.font=[UIFont systemFontOfSize:12*kAppScale];
    [nextBtn addTarget:self action:@selector(nextBtnEvent) forControlEvents:UIControlEventTouchUpInside];
    [foruV addSubview:nextBtn];
  _scrollView.contentSize=CGSizeMake(SCREEN_WIDTH, foruV.bottom+10*kAppScale);
}
- (void)teleEvent{
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",_telestr];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self.view addSubview:callWebview];

}
#pragma mark -- 点击事件
- (void)btn{
//    [self.view endEditing:YES];
    companyDetailsViewController*companyDetailsVC=[[companyDetailsViewController alloc]init];
    [self .navigationController pushViewController:companyDetailsVC animated:YES];
  
}
-(void)tuPianBtnClick{
    companyDetailsViewController*companyDetailsVC=[[companyDetailsViewController alloc]init];
    companyDetailsVC.uidcompany=[NSString stringWithFormat:@"%@",[_dic objectForKey:@"uid"]];
    [self .navigationController pushViewController:companyDetailsVC animated:YES];

}
- (void)nextBtnEvent{

    
}
-(NSString *)customNavigationRightItemTitle {
    return @"个人资料";
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
